﻿using System.Drawing;
using System.IO;
using System.Windows.Forms;


namespace EasyTrayIcon
{
	 public sealed class TrayIcon
	 {
		  private NotifyIcon notifyIcon = new NotifyIcon();	// NotifyIcon object

		  // Declaring Event
		  public delegate void StatusChanged( object sender , SystemTrayIconEventArgs e );
		  public event StatusChanged OnStatusChanged;

		 

		  public void setIcon(Icon icon) { 
				
				notifyIcon.Icon = icon;
				notifyIcon.Visible = true;
		  }

		  public void setIcon( string text ) {

				setIcon(GetIcon(text ));
				//ICON icon = new ICON(
		  
		  }




		  public  Icon GetIcon( string text ) {
				//Create bitmap, kind of canvas
			
				Bitmap bitmap = new Bitmap( 16 , 16 );

				//Icon icon = new Icon( @"Images\PomoDomo.ico" );
				System.Drawing.Font drawFont = new System.Drawing.Font( "Verdana" , 16 , FontStyle.Bold );
				System.Drawing.SolidBrush drawBrush = new System.Drawing.SolidBrush( System.Drawing.Color.Black );

				System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage( bitmap );

				graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixel;
				//graphics.DrawIcon( icon , 0 , 0 );


				SolidBrush blueBrush = new SolidBrush( Color.Blue );

				// Create rectangle.
				Rectangle rect = new Rectangle( 0 , 0 , 16 , 16 );

				// Fill rectangle to screen.
				graphics.FillRectangle( blueBrush , rect );


				graphics.DrawString( text , drawFont , drawBrush , 0 , 0 );

				//To Save icon to disk
				//bitmap.Save( "icon.ico" , System.Drawing.Imaging.ImageFormat.Icon );

				Icon createdIcon = Icon.FromHandle( bitmap.GetHicon() );

				drawFont.Dispose();
				drawBrush.Dispose();
				graphics.Dispose();
				bitmap.Dispose();

				return createdIcon;
		  }


	 }//end class
}//end namespace